package com.example.nonacademic_education.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.nonacademic_education.data.response.AdminIdAndName;
import com.example.nonacademic_education.data.response.AdminVo;
import com.example.nonacademic_education.entity.Admin;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author xinmiao
 * @description
 * @date 2023/3/28 13:33
 */
public interface AdminDao extends BaseMapper<Admin> {
    List<AdminVo> getListByNameAndDepartment(Integer page, Integer size, String name, Long departmentId);

    Integer countByNameAndDepartment(String name, Long departmentId);

    Integer addOne(Admin admin);

    Integer updateOneById(Admin admin);

    Integer deleteOneById(Long id);

    @Select("select * from admin where username = #{username} and password = #{password}")
    Integer selectOne(Admin admin);

    @Select("select a.*,d.name as departmentName from admin a left join department d on a.department_id = d.id where a.username = #{username} and a.password = #{password} and a.is_del=0 limit 1")
    AdminVo findOneByUsernameAndPassword(String username, String password);


    List<AdminIdAndName> getOneByName(String name, Long departmentId);

    @Select("select authority from admin where id=#{adminId} and is_del=0")
    Integer findAuthorityById(Long adminId);

    Integer updateOneself(Admin admin);

    @Update("update admin set password=#{password} where username=#{username}")
    Integer resetPassword(String username, String password);

    @Select("select id from admin where username=#{username} and is_del=0")
    Long getIdByUsername(String username);

    @Select("select a.*,d.name as departmentName from admin a left join department d on a.department_id = d.id where a.username = #{username} and a.is_del=0 limit 1")
    AdminVo getOneByUsername(String string);

    @Select("select authorities from admin where id=#{id} and is_del=0")
    String getAuthorities(Long id);

    @Select("select password from admin where username=#{username} and is_del=0 limit 1")
    String getPasswordByUsername(String username);

    @Select("select department_id from admin where username=#{loginIdAsString}")
    Long getDepartmentIdByUsername(String loginIdAsString);

    @Select("")
    List<Admin> getContacts(String name);

    @Update("update admin set able=#{able} where username=#{id}")
    Integer enableAccount(String id, int able);
}
